package br.com.fipsi.praticassgr.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.fipsi.praticassgr.banco.BaseDeDados;

/**
 * Servlet implementation class Remover
 */
@WebServlet("/Remover")
public class Remover extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Remover() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String codigo = request.getParameter("codigo");
		for (int i = 0; i < BaseDeDados.lista.size(); i++) {
			if (BaseDeDados.lista.get(i).getCodigo() == Integer.parseInt(codigo)) {
				BaseDeDados.lista.remove(i);
				response.sendRedirect("/praticas-sgr/listar.jsp");
				response.getWriter().close();
			}
		}
	}
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String codigo = request.getParameter("codigo");
		for (int i = 0; i < BaseDeDados.lista.size(); i++) {
			if (BaseDeDados.lista.get(i).getCodigo() == Integer.parseInt(codigo)) {
				BaseDeDados.lista.remove(i);
				response.sendRedirect("/praticas-sgr/listar.jsp");
				response.getWriter().close();
			}
		}
	}

}
